package com.jdcjk.project.main.view;

import android.annotation.SuppressLint;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.jdcjk.R;

/**
 * Created by Administrator on 2016/12/16 0016.
 */
@SuppressLint({"NewApi", "ValidFragment"})
public class BindCarDialog extends DialogFragment {
    private final String TAG = BindCarDialog.class.getSimpleName();
    private Context context;
    private View.OnClickListener onClickListener;
    private EditText sim_editText;
    //确定按钮
    private Button addCarDetermine_button;

    public BindCarDialog(Context context, View.OnClickListener onClickListener) {
        this.context = context;
        this.onClickListener = onClickListener;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View viewContent = inflater.inflate(R.layout.dialog_bind_car, container, false);
        //去掉dialog默认标题
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        //Sim码输入框
        sim_editText = (EditText) viewContent.findViewById(R.id.dialog_sim_et);
        //二维码扫描功能
        ImageButton dialogSimScan_button = (ImageButton) viewContent.findViewById(R.id.dialog_sim_scan_btn);
        dialogSimScan_button.setOnClickListener(onClickListener);
        //确定按钮
        addCarDetermine_button = (Button) viewContent.findViewById(R.id.dialog_add_car_determine_btn);
        addCarDetermine_button.setOnClickListener(onClickListener);
        //取消按钮
        Button addCarCancle_button = (Button) viewContent.findViewById(R.id.dialog_add_car_cancle_btn);
        //取消按钮点击监听
        addCarCancle_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BindCarDialog.this.dismiss();
            }
        });
        return viewContent;
    }


    /**
     * 获得输入的sim码
     *
     * @return 未输入则返回null
     */
    public String getSimNumber() {
        String SimNumber = sim_editText.getText().toString().trim();
        return SimNumber.length() == 0 || SimNumber.equals("") ? null : SimNumber;
    }

    //获得输入的sim码
    public void setSimNumber(String iemiNumber) {
        sim_editText.setText(iemiNumber != null ? iemiNumber : "");
    }

    /**
     * 设置确定按钮可否点击
     *
     * @param isClickadble 可否点击
     */
    public void setDetermineBtnClicked(boolean isClickadble) {
        addCarDetermine_button.setClickable(isClickadble);
    }

}
